﻿namespace SenenFernandez.SmartExtensionMethods
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    /// <summary>
    /// Extension Methods for Database.
    /// </summary>
    public static class Data
    {
        /// <summary>
        /// Converts generic list to DataTable.
        /// </summary>
        public static DataTable ToDataTable<T>(this IEnumerable<T> list) where T : IConvertible
        {
            var table = new DataTable();
            if (list != null)
            {
                table.Columns.Add(typeof (T).ToString());
                foreach (var item in list)
                {
                    table.Rows.Add(item);
                }
            }
            return table;
        }
    }
}